package service;

import dao.ImplementUser;
import pojo.Userregist;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/registServlet")
public class RegistServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        String usename = req.getParameter("usename");
        String password = req.getParameter("password");
        String telephone = req.getParameter("telephone");
        String age = req.getParameter("age");
        String gender = req.getParameter("gender");
        ImplementUser implement = new ImplementUser();
        Userregist userlist = new Userregist();
        userlist=implement.listuser(usename,password,age,telephone,gender);
        boolean flag = implement.addregist(userlist);
        if (!flag) req.getRequestDispatcher("/failServlet").forward(req, resp);
        else {
            resp.sendRedirect(req.getContextPath() + "/login.jsp");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
